package com.example.user.service.impl;


import com.example.common.result.PageBean;
import com.example.model.auth.dto.UserDTO;
import com.example.model.auth.dto.UserLoginDTO;
import com.example.model.customer.pojo.Customer;
import com.example.user.mapper.CustomerMapper;
import com.example.user.service.CustomerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
public class CustomerServiceimpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Transactional
    @Override
    public void delete(List<Integer> ids) {
        customerMapper.delete(ids);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, String phone) {
        PageHelper.startPage(page,pageSize);
        List<Customer> list = customerMapper.list(name, phone);
        //强转
        Page<Customer> p = (Page<Customer>) list;
        PageBean pb =  new PageBean(p.getTotal(),p.getResult());
        return pb;

    }

    @Override
    public void save(Customer customer) {
        customerMapper.save(customer);
    }

    @Override
    public Customer selectById(Integer id) {
        return customerMapper.selectById(id);
    }

    @Override
    public void updateById(Customer customer) {
        customerMapper.updateById(customer);
    }
}

